package com.ys.erp.framework.validator;

import com.ys.erp.framework.annotation.valid.PhoneValid;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author lwj
 * @date 2023/9/21
 */
public class PhoneValidator implements ConstraintValidator<PhoneValid, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        return isEff(value);
    }

    public boolean isEff(String value) {
        if (StringUtils.isEmpty(value)) {
            return true;
        }
        String htmlPattern = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
        Pattern pattern = Pattern.compile(htmlPattern);
        Matcher matcher = pattern.matcher(value);
        return matcher.matches();
    }


}
